
import Vue from 'vue'
import VueRouter from 'vue-router'


Vue.use(VueRouter)

const routes = [

  // 登录页
  {
    path: '/login',
    name: 'MyLogin',
    meta:{
      title:"登录"
    },
    component: () => import('@/views/login/MyLogin.vue')
  },

  {
    path: '/',
    name: 'MyLayout',
    
    component: () => import('@/views/layout/MyLayout.vue'),
    children: [
      {
        path: '',
        name: 'Home',
        meta:{
          title:"我的首页"
        },
        component: () => import('@/views/Home.vue')
      },
      // 内容管理
      {
        path:"article",
        name:"Article",
        meta:{
          title:"内容管理"
        },
        component: () => import('@/views/article/MyArticle.vue')
      },
      // 文章发布
      {
        path:"publish",
        name:"Publish",
        meta:{
          title:"发布文章"
        },
        component: () => import('@/views/publish/MyPublish.vue')
      },
      // 素材
      {
        path:"image",
        name:"Image",
        meta:{
          title:"素材管理"
        },
        component: () => import('@/views/image/MyImage.vue')
      },
      // 评论管理
      {
        path:"comment",
        name:"Comment",
        meta:{
          title:"评论管理"
        },
        component: () => import('@/views/comment/MyComment.vue')
      },
      // 个人设置
      {
        path:"settings",
        name:"Setting",
        meta:{
          title:"个人设置"
        },
        component:() => import('@/views/setting/MySetting.vue')
      },
      // 粉丝管理
      {
        path:'fans',
        name:'Fans',
        meta:{
          title:"个丝管理"
        },
        component:() => import('@/views/fans/MyFans.vue')
      }
    ]

  },


  

]

const router = new VueRouter({
  routes
})

router.beforeEach((to,from,next)=>{
  let user = JSON.parse(window.localStorage.getItem('user'))
  if(to.path !== '/login'){
    if(user){
      next()
    }else{
      next('/login')
    }
  }else{
    next()
  }
  
})

export default router


